import {Injectable} from '@angular/core';
import {NzMessageService} from 'ng-zorro-antd/message';
import {NzModalService} from 'ng-zorro-antd/modal';
import {NzNotificationService} from 'ng-zorro-antd/notification';

@Injectable({
  providedIn: 'root'
})
export class LayerService {

  constructor(public message: NzMessageService,
              public modal: NzModalService,
              public notification: NzNotificationService) {
  }

  messageSuccess(content: string) {
    this.message.create('success', content);
  }

  messageError(content: string) {
    this.message.create('error', content);
  }

  messageWarning(content: string) {
    this.message.create('warning', content);
  }

  modalInfo(content: string): void {
    this.modal.info({
      nzTitle: '信息提示',
      nzContent: content,
    });
  }

  modalSuccess(content: string): void {
    this.modal.success({
      nzTitle: '成功提示',
      nzContent: content,
    });
  }

  modalError(content: string): void {
    this.modal.error({
      nzTitle: '失败提示',
      nzContent: content,
    });
  }

  modalWarning(content: string): void {
    this.modal.warning({
      nzTitle: '警告提示',
      nzContent: content,
    });
  }

  //问询
  modalConfirm(title: string, callback: any, content?: any): void {
    this.modal.confirm({
      nzTitle: title,
      nzContent: content,
      nzOnOk: () =>
        callback(true),
      nzOnCancel: () =>
        callback(false),
    });
  }

  modalDeleteConfirm(title: string, callback: any, content?: any): void {
    this.modal.confirm({
      nzTitle: title,
      nzContent: content,
      nzOkText: '确定删除',
      nzOkType: 'danger',
      nzOnOk: () => callback(true),
      nzCancelText: '取消',
      nzOnCancel: () => callback(false)
    });
  }

  notificationSuccess(content: string): void {
    this.notification.create(
      'success',
      '成功通知',
      content
    );
  }

  notificationInfo(content: string): void {
    this.notification.create(
      'info',
      '信息通知',
      content
    );
  }

  notificationWarning(content: string): void {
    this.notification.create(
      'warning',
      '警告通知',
      content
    );
  }

  notificationError(content: string): void {
    this.notification.create(
      'error',
      '错误通知',
      content
    );
  }

  // tslint:disable-next-line:typedef
  createTplModal(title, tplContent, callback, content?) {
    this.modal.create({
      nzTitle: title,
      nzContent: tplContent,
      nzOkText: '确定',
      nzOnOk: () => callback(true),
      nzCancelText: '取消',
      nzOnCancel: () => callback(false),
    });
  }
}
